package com.orangesoft.common.util;



/**
 * 私人验证工具类
 *
 * @author xhy
 */
public class SeaValidateUtils {
    public static boolean isValidPhoneNumber(String phoneNumber) {
        // 检查输入格式是否正确
        if (phoneNumber == null || phoneNumber.isEmpty()) {
            return false;
        }

        // 使用正则表达式匹配手机号码格式
        String regex = "^1[3456789]\\d{9}$";
        return phoneNumber.matches(regex);
    }

    public static boolean isIdNumberValid(String idNumber) {
        // 身份证号的长度必须为18位
        if (idNumber.length() != 18) {
            return false;
        }

        // 前17位必须是数字
        String digits = idNumber.substring(0, 17);
        if (!digits.matches("^[0-9]*$")) {
            return false;
        }

        // 判断校验码是否合法
        String lastDigit = idNumber.substring(17);
        String[] factors = {"7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2"};
        String[] validationCodes = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};

        int sum = 0;
        for (int i = 0; i < 17; i++) {
            sum += Integer.parseInt(digits.substring(i, i+1)) * Integer.parseInt(factors[i]);
        }

        int remainder = sum % 11;
        String validationCode = validationCodes[remainder];

        return lastDigit.equals(validationCode);
    }


}
